package com.croqodile {
    import flash.display.MovieClip;
    import flash.system.Security;
    import com.senocular.utils.Output;
    import flash.utils.Timer;
    import com.croqodile.RouterConnection;
    import flash.events.*;
    
    public class RouterTest extends MovieClip {
	
	private static const POLICY_SERVER_HOST:String = "localhost";
	private static const POLICY_SERVER_PORT:int = 5001;

	public function RouterTest() {
	    stage.addChild(new Output());
	    Security.loadPolicyFile("xmlsocket://" + POLICY_SERVER_HOST + ":" + POLICY_SERVER_PORT);
	    Output.trace("Beginning test...");
	    
	    var routerCon:RouterConnection = RouterConnection.createNew(onMessageReceived);
	    
	    var myTimer:Timer = new Timer(1000, 0); // 1 second
	    myTimer.addEventListener(TimerEvent.TIMER, function():void {
		    routerCon.sendMessage("Hello there.");
		});
	    myTimer.start();
	}
	
	public function onMessageReceived(msg:String):void {
	    Output.trace("Received: " + msg + "\n");
	}
    }
}


